﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    class ConvertToAnySyst
    {
        static void Main(string[] args)
        {
            Console.Write("Enter  number: ");
            string number = Console.ReadLine();
            StringBuilder result = new StringBuilder();
            int decimalNum = 0;
            int bit = 0;
            int count = number.Length-1;
            int s = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            //int d = int.Parse(Console.ReadLine());
            //convert to decimal
            for (int i = 0; i<number.Length; i++)
            {
                decimalNum = decimalNum + int.Parse(number[i].ToString()) * (int)Math.Pow(s, count);
                count--;
            }
            Console.WriteLine("The decimal representation of {0} is: {1}", number, decimalNum);    
            //convert to d base number
            if (d >= 10)
            {
                while (decimalNum > 0)
                {
                    switch (decimalNum % 16)
                    {
                        case 10:
                            result.Append('A');
                            break;
                        case 11:
                            result.Append('B');
                            break;
                        case 12:
                            result.Append('C');
                            break;
                        case 13:
                            result.Append('D');
                            break;
                        case 14:
                            result.Append('E');
                            break;
                        case 15:
                            result.Append('F');
                            break;
                        default:
                            result.Append(decimalNum % d);
                            break;
                    }
                    decimalNum = decimalNum / d;
                }
            }
            else
            {
                while (decimalNum > 0)
                {
                    bit = decimalNum % d;
                    decimalNum = decimalNum / d;
                    result.Append(bit);
                }
            }
            string finalHex = result.ToString();
            for (int i = result.Length - 1; i >= 0; i--)
            {
                Console.Write((char)result[i]);
            }
            Console.WriteLine();
 
            }
        }
    

